'''继承，重写，父类引用指向子类对象
    多态
    综合程序
'''

from abc import ABCMeta, abstractmethod
from random import randint, randrange


class Figher(object, metaclass=ABCMeta):

    __slots__ = ('_name', '_hp')

    def __init__(self, name, hp):
        '''初始化
        name:名字
        hp；血量
        '''
        self._name = name
        self._hp = hp

    @property
    def name(self):
        return self._name

    @property
    def hp(self):
        return self._hp

    @hp.setter
    def hp(self, hp):
        self._hp = hp if hp >= 0 else 0

    @property
    def alive(self):
        return self._hp > 0

    @abstractmethod
    def attack(self, other):
        '''攻击
        ：param other:攻击对象
        '''
        pass


class Ultrman(Figher):
    '''英雄
    '''

    __slots__ = ('_name', '_hp', '_mp')

    def __init__(self, name, hp, mp):
        self._mp = mp
        super().__init__(name, hp)
        '''初始化
            paramname:名字
            paramHp:生命值
            paramMp:魔法值
            '''

    def attack(self, other):
        other.hp -= randint(15, 25)

    def huge_attack(self, other):
        if self._mp >= 50:
            self._mp -= 50
            injury = other.hp * 3 // 4
            injury = injury if injury >= 50 else 50
            other.hp -= injury
            return True
        else:
            self.attack(other)
            return False

    def magic_attack(self, other):
        '''魔法攻击
        param others:被攻击群体
        return ： 使用魔法成功返回Ture 否则返回false
        '''
        if self._mp >= 20:
            self._mp -= 20
            for temp in other:
                if temp.attack:
                    temp.hp -= randint(10, 15)
                    return True
                else:
                    return False

    def __str__(self):
        return '~~~~~%s 奥科曼~~~~~\n' % self._name +\
            '生命值：%d \n' % self._hp +\
            '魔法值：%d \n' % self._mp


class Monster(Figher):
    '''小怪兽'''

    __slots__ = ('_name', '_hp')

    def attack(self, other):
        other.hp -= randint(10, 20)

    def __str__(self):
        return '~~~~小怪兽~~~~~\n' % self._name +\
            '生命值 : %d\n' % self._hp


def is_any_alive(monsters):
    """判断有没有小怪兽是活着的"""
    for monster in monsters:
        if monster.alive > 0:
            return True

    return False


def selest_alive_one(monsters):
    '''选中一只活着的小怪兽'''
    monsters_len = len(monsters)
    while True:
        index = randrange(monsters_len)
        monster = monsters(index)
        if monster.alive > 0:
            return monster